import { t } from '@/locales/i18n';

import {
  FlowNodeOutputTypeEnum,
  FlowNodeTemplateTypeEnum,
  FlowNodeTypeEnum,
  NodeOutputKeyEnum,
  WorkflowIOValueTypeEnum,
} from '../../constant';
import { FlowNodeOutputItemType } from '../../io';
import { FlowNodeTemplateType } from '../../node';
import { Input_Template_UserChatInput } from '../input';
import { getHandleConfig } from '../utils';

export const userFilesInput: FlowNodeOutputItemType = {
  id: NodeOutputKeyEnum.userFiles,
  key: NodeOutputKeyEnum.userFiles,
  label: t('app:workflow.user_file_input'),
  description: t('app:workflow.user_file_input_desc'),
  type: FlowNodeOutputTypeEnum.static,
  valueType: WorkflowIOValueTypeEnum.arrayString,
};

export const WorkflowStart: FlowNodeTemplateType = {
  id: FlowNodeTypeEnum.workflowStart,
  templateType: FlowNodeTemplateTypeEnum.systemInput,
  flowNodeType: FlowNodeTypeEnum.workflowStart,
  sourceHandle: getHandleConfig(false, true, false, false),
  targetHandle: getHandleConfig(false, false, false, false),
  avatar: 'workflowStart.svg',
  name: t('template.workflow_start'),
  intro: t('workflow.workflow_start_desc'),
  forbidDelete: true,
  unique: true,
  courseUrl: '/docs/workflow/modules/input/',
  version: '481',
  inputs: [{ ...Input_Template_UserChatInput, toolDescription: t('user_question') }],
  outputs: [
    {
      id: NodeOutputKeyEnum.userChatInput,
      key: NodeOutputKeyEnum.userChatInput,
      label: t('core.module.input.label.user question'),
      type: FlowNodeOutputTypeEnum.static,
      valueType: WorkflowIOValueTypeEnum.string,
    },
  ],
  isFolded: true,
};

export const isWorkflowStartOutput = (key?: string) =>
  !!WorkflowStart.outputs.find((output) => output.key === key);
